package model
{
	//斗地主游戏模型
	
	import flash3.framework.Singleton;
	
	import view.game.GameConst;
	
	import vo.GamePlayer;
	import vo.GameServer;
	import vo.MoneyPoolItem;
	import vo.RoomUser;
	import vo.ServerRunInfo;
	import vo.TableInfo;
	import vo.UserInfo;
	import vo.UserScore;
	import vo.UserStatus;

	public class GameModel
	{
		public var tableInfo:TableInfo;		//桌子信息
		public var gamePlayers:Array = [];		//游戏玩家
		public var gameScore:Array = [];		//游戏成绩
		public var userAccount:Array = [];		//玩家昵称
		public var backCard:Array = [];		//底牌
		public var gameStatus:int;				//游戏状态
		public var allowLookon:Boolean			//运行旁观
		public var baseScore:int;				//基础积分
		
		public var preUser:int;				//先前玩家
		public var curUser:int;				//当前玩家椅子ID
		public var curScorePhase:int;			//叫牌阶段
		public var preScorePhase:int;			//之前阶段
		public var curBrightTime:int;			//当前名牌倍数
		public var preBrightTime:int;			//先前明牌倍数
		public var preLandScore:int;			//先前分数
		public var curLandScore:int;			//当前叫分
		
		public var bombTime:int;				//炸弹倍数
		
		public var outCardUser:int;			//出牌玩家
		public var outCardData:Array = [];		//当前出牌
		
		
		public var newTurn:int;				//一轮开始
		public var passUser:int;				//放弃玩家
		
		public var landlordUser:int;			//地主玩家
		public var landlordScore:int;			//地主叫分
		
		public var gameTax:uint;				//游戏税收
		public var gamePresentTax:uint;		//游戏捐税
		
		public var allowDouble:Boolean;		//允许加倍
		public var doubleUser:uint;			//加倍玩家
		public var isDouble:Boolean;			//是否加倍
		
		public var brightUser:uint;			//明牌玩家

		public var poolItem:MoneyPoolItem;		//奖金池
		public var gameServer:GameServer;
		public var serverRunInfo:ServerRunInfo;//服务器运行信息
		
		public var lostGold:int;				//逃跑损失金币
		public var lostScore:int;				//逃跑损失汽油毛豆等
		
		public function GameModel()
		{
			curBrightTime = 1;
			serverRunInfo = new ServerRunInfo();
			var i:uint =0;
			for(i=0;i<3;i++)
			{
				gamePlayers[i] = new GamePlayer();
				gameScore[i] = 0;
				userAccount[i] = "aaa";
			}
//			gameScore[0] = 123;
//			gameScore[1] = -896123;
//			gameScore[2] = 123;
		}
		
		static public function get i():GameModel
		{
			return Singleton.getInstanceOrCreate(GameModel) as GameModel;
		}
		
		public function reset():void
		{
			curBrightTime = 1;
			gameScore.length = 0;
			outCardData.length = 0;
			backCard.length = 0;
			for(var i:uint = 0; i < 3; i++)
			{
				(gamePlayers[i] as GamePlayer).reset();
			}
		}
		
		public function getUserStatusByUserID(userID:uint):UserStatus
		{
			if(!tableInfo) return null;
			for(var i:uint = 0; i < gamePlayers.length; i++)
			{
				var userStatus:UserStatus = tableInfo.userStatus[i];
				if(userStatus && userStatus.dwUserID == userID)
					return userStatus;
			}
			return null;
		}
	}
}